<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of als_solve_rx_2</title>
  <meta name="keywords" content="als_solve_rx_2">
  <meta name="description" content="Computes an approximate low-rank solution for 2D case (Method 2)">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">solve</a> &gt; als_solve_rx_2.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/solve&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>als_solve_rx_2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Computes an approximate low-rank solution for 2D case (Method 2)</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [x]=als_solve_rx_2(mat, rhs, tol, maxit, x0, drx, nswp) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Computes an approximate low-rank solution for 2D case (Method 2)
   [x]=ALS_SOLVE_RX(MAT, RHS, [TOL], [MAXIT],[X0],[DRX], [NSWP])
   Finds a solution to 2D TTM matrix MAT using the ALS to a 2D TT tensor
   with rank rx, but the RHS and X are represented as full vectors.


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the QTT-Tucker</li><li><a href="../../tt2/@tt_matrix/norm.html" class="code" title="function [nrm] = norm(t,varargin)">norm</a>	Matrix norm of the TT-matrix</li><li><a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>	Mode sizes of the TT-matrix</li><li><a href="../../tt2/@tt_tensor/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the TT-tensor</li><li><a href="../../tt2/@tt_tensor/size.html" class="code" title="function [sz] = size(tt,dim)">size</a>	Mode sizes of the TT-tensor</li><li><a href="../../tt2/core/tt_mat_full_vec.html" class="code" title="function [y]=tt_mat_full_vec(tt,x)">tt_mat_full_vec</a>	Multiplication of the TT-matrix by full vector in TT1.0 format</li><li><a href="als_solve_rx.html" class="code" title="function [x]=als_solve_rx(mat, rhs, tol, drx, nswp, addswp)">als_solve_rx</a>	Computes an approximate low-rank solution for 2D case</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="dmrg_solve2.html" class="code" title="function [x, sweeps]=dmrg_solve2(A, y, eps,varargin)">dmrg_solve2</a>	Solution of linear systems in TT-format via DMRG iteration</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [x]=als_solve_rx_2(mat, rhs, tol, maxit, x0, drx, nswp)</a>
0002 <span class="comment">%Computes an approximate low-rank solution for 2D case (Method 2)</span>
0003 <span class="comment">%   [x]=ALS_SOLVE_RX(MAT, RHS, [TOL], [MAXIT],[X0],[DRX], [NSWP])</span>
0004 <span class="comment">%   Finds a solution to 2D TTM matrix MAT using the ALS to a 2D TT tensor</span>
0005 <span class="comment">%   with rank rx, but the RHS and X are represented as full vectors.</span>
0006 <span class="comment">%</span>
0007 <span class="comment">%</span>
0008 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0009 <span class="comment">%</span>
0010 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0011 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0012 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0013 <span class="comment">%</span>
0014 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0015 <span class="comment">%ivan.oseledets@gmail.com</span>
0016 <span class="comment">%---------------------------</span>
0017 
0018 
0019 nrmf = <a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(rhs);
0020 
0021 <span class="keyword">if</span> (nargin&lt;3)||(isempty(tol))
0022     tol=1e-12;
0023 <span class="keyword">end</span>;
0024 <span class="keyword">if</span> (nargin&lt;4)||(isempty(maxit))
0025     maxit=2;
0026 <span class="keyword">end</span>;
0027 <span class="keyword">if</span> (nargin&lt;5)||(isempty(x0))
0028     x0 = zeros(<a href="../../tt2/@tt_matrix/size.html" class="code" title="function [sz] = size(tt)">size</a>(rhs));
0029 <span class="keyword">end</span>;
0030 <span class="keyword">if</span> (nargin&lt;6)||(isempty(drx))
0031     drx=1;
0032 <span class="keyword">end</span>;
0033 <span class="keyword">if</span> (nargin&lt;7)||(isempty(nswp))
0034     nswp=4;
0035 <span class="keyword">end</span>;
0036 
0037 
0038 x=x0;
0039 cur_rhs = rhs - <a href="../../tt2/core/tt_mat_full_vec.html" class="code" title="function [y]=tt_mat_full_vec(tt,x)">tt_mat_full_vec</a>(mat,x);
0040 
0041 err = <a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(cur_rhs)/nrmf;
0042 <span class="keyword">if</span> (err&lt;tol) 
0043     <span class="keyword">return</span>;
0044 <span class="keyword">end</span>;
0045 
0046 spunct = 0;
0047 err_old = err;
0048 <span class="keyword">for</span> i=1:maxit
0049     cur_x = <a href="als_solve_rx.html" class="code" title="function [x]=als_solve_rx(mat, rhs, tol, drx, nswp, addswp)">als_solve_rx</a>(mat, cur_rhs, tol, drx, nswp);    
0050 <span class="comment">%     cur_rhs = cur_rhs - tt_mat_full_vec(mat, cur_x);</span>
0051     
0052     x = x+cur_x;
0053     cur_rhs = rhs - <a href="../../tt2/core/tt_mat_full_vec.html" class="code" title="function [y]=tt_mat_full_vec(tt,x)">tt_mat_full_vec</a>(mat,x);
0054     
0055     err = <a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(cur_rhs)/nrmf;
0056     conv_fact = err_old/err;
0057     
0058     fprintf(<span class="string">'als_solve_full: iter = %d, resid = %3.3e, conv_fact=%3.3f\n'</span>, i, err, conv_fact);
0059     
0060     <span class="keyword">if</span> (conv_fact&lt;1.2)
0061         spunct = spunct+1;
0062 <span class="comment">%         if (rx&lt;15)</span>
0063 <span class="comment">%             rx=rx+1;</span>
0064 <span class="comment">%         end;</span>
0065     <span class="keyword">end</span>;
0066     <span class="keyword">if</span> (spunct&gt;3)
0067         <span class="keyword">break</span>; <span class="comment">% shit happened - we've stagnated</span>
0068     <span class="keyword">end</span>;
0069     err_old = err;
0070     <span class="keyword">if</span> (err&lt;tol)
0071         <span class="keyword">break</span>;
0072     <span class="keyword">end</span>;
0073 
0074 <span class="comment">%     if (rx==10)</span>
0075 <span class="comment">%         break;</span>
0076 <span class="comment">%     end;</span>
0077 <span class="comment">%     if (conv_fact&lt;1.01)</span>
0078 <span class="comment">%         break;</span>
0079 <span class="comment">%     end;</span>
0080 <span class="keyword">end</span>;
0081 
0082 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>